<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .w {
            width: 600px;
            margin: auto;
        }

        .container {
            height: 400px;
            overflow: auto;
            position: relative;
        }
        .container::-webkit-scrollbar{
            width: 0;
        }

        .inner {
            width: 300%;
            display: flex;
        }

        .section {
            width: 600px;
            height: 360px;
            font-size: 40px;
            padding: 10px;
        }

        .section:nth-child(1) {
            background-color: lightcoral;
        }

        .section:nth-child(2) {
            background-color: lightseagreen;
        }

        .section:nth-child(3) {
            background-color: lightskyblue;
        }

        .action {
            margin-bottom: 10px;
        }

        .action button {
            padding: 4px 10px;
        }
    </style>
</head>

<body>
    <div class="action w">
        <button>热门推荐</button>
        <button>今日头条</button>
        <button>时政要闻</button>
    </div>
    <div class="container w">
        <div class="inner">
            <div class="section">热门推荐</div>
            <div class="section">今日头条</div>
            <div class="section">时政要闻</div>
        </div>
    </div>
    <script>
        // 获取元素对象
        var btns = document.querySelectorAll('.action button')
        var inner = document.querySelector('.inner')
        btns.forEach(function (btn, index) {
            btn.onclick = function () {
                // console.log(btn);
                // 获取当前按钮对应的内容位置信息
                // console.log(inner.children[index].offsetLeft);
                // 移动滚动条位置
                inner.parentElement.scrollTo({
                    left: inner.children[index].offsetLeft,
                    behavior: "smooth"
                })
            }
        })
    </script>
</body>

</html>